package com.kangyi.user.mapper;

import com.kangyi.user.annotation.AutoFill;
import com.kangyi.dto.ChangePhoneDTO;
import com.kangyi.dto.ForgotPasswordDTO;
import com.kangyi.dto.PasswordEditDTO;
import com.kangyi.entity.User;
import com.kangyi.enumeration.OperationType;
import com.kangyi.vo.UserVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author Blank
 * @version 1.0
 */
@Mapper
public interface UserMapper {


    User getUser(String name, String phone);

    @Insert("insert into user(phone, name, password, headshot,status, create_user, update_user,create_time,update_time) values " +
            "(#{phone},#{name},#{password},#{headshot},#{status},#{createUser},#{updateUser},#{createTime},#{updateTime})")
    @AutoFill(value = OperationType.INSERT)
    void insert(User build);


    @Select("select * from user where name = #{name}")
    User getName(String name);

    @AutoFill(value = OperationType.UPDATE)
    void update(User user);


    @Update("update user set password = #{newPassword},update_time=#{updateTime},update_user=#{updateUser} where id = #{id}")
    @AutoFill(value = OperationType.UPDATE)
    void updateByPassword(PasswordEditDTO passwordEditDTO);

    @Select("select * from user where id = #{id}")
    UserVO selectById(Integer id);

    @Update("update user set password = #{newPassword} where phone = #{phone}")
    @AutoFill(value = OperationType.UPDATE)
    void forgotPassword(ForgotPasswordDTO forgotPasswordDTO);

    @Update("update user set phone = #{phone} where id = #{id}")
    void updateByPhone(ChangePhoneDTO changePhoneDTO);

    List<UserVO> getUsersByIds(List<Integer> userIds);

    @Select("select * from user where id = #{id};")
    User getUsersById(Integer id);
}
